<template>
  <div style="padding: 15px">
    <vxe-toolbar id="toolbarId_re9" :custom="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="funcFilter">查询</el-button>
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      border
      resizable
      stripe
      align="center"
      highlight-current-row
      highlight-hover-row
      row-id="id"
      height="700"
      :data="tableData"
      :loading="loading"
      remote-sort
      @sort-change="sortList"
    >
      <vxe-table-column field="groupName" title="组织机构"  min-width="120" sortable />
      <vxe-table-column>
        <vxe-table-column field="serialNumber" title="组织编码" min-width="130" sortable />
        <template v-slot:header>
          <el-input v-model="listQuery.serialNumber" placeholder="组织编码" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="times" title="充值数量" show-header-overflow show-overflow min-width="250" sortable />
          <template v-slot:header>
          <el-row>
            <el-col :span="11">
              <el-input type="text" v-model="listQuery.rechargeQuantityLower" placeholder="下限" clearable @blur="inputBlur" />
            </el-col>
            <el-col :span="11" :offset="2">
              <el-input type="text" v-model="listQuery.rechargeQuantityUpper" placeholder="上限" clearable  @blur="inputBlur" />
            </el-col>
          </el-row>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="uses" title="使用数量" show-header-overflow show-overflow min-width="200" sortable />
          <template v-slot:header>
          <el-row>
            <el-col :span="11">
              <el-input type="text" v-model="listQuery.quantityUsedLower" placeholder="下限" clearable  @blur="inputBlur" />
            </el-col>
            <el-col :span="11" :offset="2">
              <el-input type="text" v-model="listQuery.quantityUsedUpper" placeholder="上限" clearable  @blur="inputBlur" />
            </el-col>
          </el-row>
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column field="surplus" title="剩余数量" show-header-overflow show-overflow min-width="200" sortable />
          <template v-slot:header>
          <el-row>
            <el-col :span="11">
              <el-input type="text" v-model="listQuery.remainingQuantityLower" placeholder="下限" clearable  @blur="inputBlur" />
            </el-col>
            <el-col :span="11" :offset="2">
              <el-input type="text" v-model="listQuery.remainingQuantityUpper" placeholder="上限" clearable  @blur="inputBlur" />
            </el-col>
          </el-row>
        </template>
      </vxe-table-column>
      <vxe-table-column field="action" title="操作" width="120" fixed="right">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="dark" content="详情" placement="top">
            <vxe-button type="text" @click="funcRiview(scope.row.groupCode)">
              <i class="el-icon-tickets" />
            </vxe-button>
          </el-tooltip>
        </template>
      </vxe-table-column>
    </vxe-table>
    <!-- <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    /> -->
    <vxe-modal v-model="modelFlang" title="详情" width="800" height="600" resize destroy-on-close>
      <compDel @fatherCancelMethod="fatherCancel" :code='code'/>
    </vxe-modal>
  </div>
</template>
<script>
import compDel from './components/detail.vue'
import request from '@/utils/request'
export default {
  name: "AccountBalance",
  components:{
    compDel
  },
  data() {
    return {
      loading:false,
      tableData:[{code:'123'}],
      modelFlang:false,
      partyGroup:[],
      code:'',
      listQuery:{
        pageNum: 1,
        pageSize: 20,
        total: 0
      }
    };
  },
  created() {
    this.findList()
  },
  methods: {
    findList(){
      this.loading = true
      let data = this.listQuery
      return new Promise(resolve=>{
        request({
          url: '/wms/outbound/accountBalance',
          method: 'put',
          params:data
        }).then(response => {
          this.tableData = response.data
          // this.listQuery.total = response.data.total
          this.loading = false
          resolve();
        })
      })
    },
    groupCodeChange(val){
      if(val){
        let obj = this.partyGroup.find(v=>v.code === val)
        this.listQuery.groupName = obj.groupName
      }else{
        this.listQuery.groupName= ''
        this.listQuery.groupCode = ''
      }

    },
    // 查询
    funcFilter() {
      this.listQuery.pageNum = 1;
      this.findList();
    },
    inputBlur(e){
      console.log(e.target.value)
      let val = e.target.value;
      let reg = /^\+?[1-9][0-9]*$/
      if(!reg.test(val))return this.$message.error('请输入正整数')
    },
    fatherCancel(){
      this.modelFlang = false
    },
    funcRiview(val){
      this.modelFlang = true
      this.code = val
    },
        // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage;
      this.listQuery.pageSize = pageSize;
      this.findList();
    },
        // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property;
        this.listQuery.sortType = order;
      } else {
        this.listQuery.sortField = "";
      }
      this.findList();
    },
  }
};
</script>
<style></style>
